import { throttle } from "@/libs/debounce";
import { ref } from "vue";

type SearchValue = string | number | undefined

interface UseSearchOption {
  inputCallBack?: Function
  defaultValue: SearchValue
}

function useSearch({ inputCallBack, defaultValue = undefined }: UseSearchOption) {

  let searchValue = ref<SearchValue>(defaultValue)

  const setSearchValue = (data: SearchValue) => {
    searchValue.value = data
  }

  const searchInput = throttle(inputCallBack ? inputCallBack : () => {
    console.error('搜索栏未配置input时间的回调函数！');
  }, 300)


  return {
    searchValue,
    setSearchValue,
    searchInput
  }
}

export default useSearch

